package com.cn.gmall.product.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.gmall.common.result.Result;
import com.cn.gmall.model.product.*;
import com.cn.gmall.product.mapper.BaseTrademarkMapper;
import com.cn.gmall.product.service.BaseTrademarkService;
import com.cn.gmall.product.service.ManageService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/product")
public class ProductApiController {
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    ManageService manageService;
    @Autowired
    BaseTrademarkService baseTrademarkService;

    /**
     * /api/product/inner/getTrademark/{tmId}
     * @param tmId
     * @return
     */
    @GetMapping("/inner/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable Long tmId){

        return baseTrademarkService.getById(tmId);
    }


    /**获取首页分类数据
     * /api/product/getBaseCategoryList
     */
    @GetMapping("/getBaseCategoryList")
    public Result getBaseCategoryList(){
//        JSONObject 对map的进一步封装 增强了部分功能
       List<JSONObject> list=manageService.getBaseCategoryList();
        return Result.ok(list);
    }


    /**
     * /api/product/inner/getSkuValueIdsMap/{spuId}
     * 根据spuId 获取到销售属性值Id 与skuId 组成的数据集
     * @param spuId
     * @return
     */
    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable Long spuId){

        return manageService.getSkuValueIdsMap(spuId);
    }

    /**
     * 根据spuId,skuId 获取销售属性数据
     * @param skuId
     * @param spuId
     * @return
     */
    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr>  getSpuSaleAttrListCheckBySku(@PathVariable Long skuId , @PathVariable Long spuId){
        return manageService.getSpuSaleAttrListCheckBySku( skuId ,spuId);
    }


    /**
     * /api/product/inner/getAttrList/{skuId}
     * 根据skuId 获取平台属性数据
     * @param skuId
     * @return
     */
    @GetMapping("/inner/getAttrList/{skuId}")
    public List<BaseAttrInfo>  getAttrList(@PathVariable Long skuId){
        return manageService.getAttrList(skuId);
    }

    /**
     * /api/product/inner/getCategoryView/{category3Id}
     * 根据三级分类id获取分类信息
     * @param category3Id
     * @return
     */
    @GetMapping("/inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id) {

        return manageService.getCategoryView(category3Id);
    }

    /**
     * /api/product/inner/getSkuPrice/{skuId}
     * * 根据skuId 获取最新的商品价格
     *
     * @param skuId
     * @return
     */
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId) {

        return manageService.getSkuPrice(skuId);
    }

    /**
     * /api/product/inner/findSpuPosterBySpuId/{spuId}
     * 根据spuId 获取海报数据
     *
     * @param spuId
     * @return
     */
    @GetMapping("/inner/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> findSpuPosterBySpuId(@PathVariable Long spuId) {

        return manageService.findSpuPosterBySpuId(spuId);
    }

    /**
     * /api/product/inner/getSkuInfo/{skuId}
     * 根据skuId获取SkuInfo
     *
     * @param skuId
     * @return
     */
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {

        return manageService.getSkuInfo(skuId);
    }


}
